package com.pdcase;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Properties;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleniumLogLevels;

public class ITCase {
	private DefaultSelenium selenium;

	@Before
	public void setUp() throws Exception {
		Properties properties = new Properties();

		properties.load(this.getClass().getClassLoader().getResourceAsStream(
				"test.properties"));

		String userId = properties.getProperty("user.id");
		String userKey = properties.getProperty("user.key");
		String host = properties.getProperty("host");
		String args = String
				.format(
						"{\"username\": \"%s\","
								+ "\"access-key\": \"%s\","
								+ "\"os\": \"Windows 2003\","
								+ "\"browser\": \"firefox\","
								+ "\"browser-version\": \"3.\","
								+ "\"job-name\": \"This is an example test\", \"record-video\": false"
								+ " }", userId, userKey);

		String testHost = properties.getProperty("seleniumrchost");

		DefaultSelenium defaultSelenium = new DefaultSelenium(testHost, 4444,
				args, String.format("http://%s", host));

		this.selenium = defaultSelenium;

		selenium.start();

		defaultSelenium.setBrowserLogLevel(SeleniumLogLevels.INFO);
	}

	public void __testHello() {
		selenium.open("/");
		assertEquals("Home", selenium.getTitle());
		selenium.type("myName", "usuario");
		selenium.click("//input[@value='Say hello!']");
		selenium.waitForPageToLoad("30000");
		assertTrue(selenium.isTextPresent("Hello usuario!"));
	}

	@Test
	public void testTracOpen() {
		selenium.open("/trac/");
		assertEquals("siatweb", selenium.getTitle());
	}

	@After
	public void tearDown() throws Exception {
		selenium.stop();
	}
}
